package com.chixing.controller;


import com.chixing.entity.Myorder;
import com.chixing.service.IMyorderService;
import com.chixing.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author smith
 * @since 2025-09-22
 */
@CrossOrigin
@RestController
@RequestMapping("/myorder")
public class MyorderController {
    @Autowired
    private IMyorderService myorderService;

    //通过id查寻订单
    @GetMapping("{orderId}")
    public Result getById(@PathVariable("orderId") Integer orderId){
        return myorderService.getById(orderId);
    }

    //下订单的前一个页面，展示商品详情，用户有效地址，有效优惠券
    @GetMapping("/orderConfirm/{userId}/{proId}")
    public Result getProductMyCouponAddress(@PathVariable("userId") Integer userId,
                                            @PathVariable("proId") Integer proId){
        return myorderService.getProductMyCouponAddress(userId,proId);
    }
    //添加订单
    @PostMapping
    public Result save(@RequestBody Myorder myorder){
        return myorderService.save(myorder);
    }

    //修改订单状态
    @PutMapping("myOrderId/{myOrderId}/myOrderStatus/{myOrderStatus}")
    public Result updateStatus(@PathVariable("myOrderId") Integer myOrderId,
                               @PathVariable("myOrderStatus") Integer myOrderStatus){
        return myorderService.updateStatus(myOrderId,myOrderStatus);
    }
    //根据订单状态查询订单
    //Integer userId,
    @GetMapping
    public Result getByStatus(
                              @RequestParam(value = "orderStatus",required = false) Integer orderStatus,
                              @RequestParam(value = "pageNUmber",required = false) Integer pageNUmber){
        if (pageNUmber == null)
            pageNUmber = 1;
        Integer userId = 1 ;
        return myorderService.getByPageAndStatus(userId,orderStatus,pageNUmber);
    }
}
